<template>
  <view class="guide-page">
    <!-- 顶部标题 -->
    <view class="guide-header">
      <view class="back-btn" @click="handleBack">
        <text class="icon">←</text>
      </view>
      <text class="header-title">{{ pageTitle }}</text>
    </view>
    
    <!-- 步骤指引 -->
    <view class="guide-content">
      <!-- 步骤列表 -->
      <view class="steps-container">
        <view 
          class="step-item"
          v-for="(step, index) in steps" 
          :key="index"
        >
          <view class="step-number">{{ index + 1 }}</view>
          <view class="step-content">
            <text class="step-title">{{ step.title }}</text>
            <text class="step-desc">{{ step.desc }}</text>
          </view>
        </view>
      </view>

      <!-- 注意事项 -->
      <view class="notice-section">
        <view class="notice-title">
          <text class="notice-icon">⚠️</text>
          <text>注意事项</text>
        </view>
        <view 
          class="notice-item"
          v-for="(notice, index) in notices" 
          :key="index"
        >
          <text class="dot">•</text>
          <text class="notice-text">{{ notice }}</text>
        </view>
      </view>
    </view>

    <!-- 底部按钮 -->
    <view class="guide-footer">
      <button class="action-btn" @click="handleAction">
        {{ actionButtonText }}
      </button>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted, computed } from 'vue'

const type = ref('oauth')

// OAuth应用的步骤
const oauthSteps = [
  {
    title: '登录开发者平台',
    desc: '使用您的账号登录开发者平台'
  },
  {
    title: '进入应用管理',
    desc: '在控制台找到并点击"应用管理"选项'
  },
  {
    title: '创建新应用',
    desc: '点击"创建应用"按钮，填写应用信息'
  },
  {
    title: '获取凭证',
    desc: '创建成功后获取 Client ID 和 Secret'
  },
  {
    title: '配置回调',
    desc: '设置授权回调地址（需使用备案域名）'
  },
  {
    title: '等待审核',
    desc: '提交审核，等待平台审核通过'
  }
]

// 访问令牌的步骤
const tokenSteps = [
  {
    title: '登录平台',
    desc: '使用您的账号登录开发者平台'
  },
  {
    title: '个人中心',
    desc: '点击右上角头像，进入个人中心'
  },
  {
    title: '找到令牌选项',
    desc: '在左侧菜单找到"访问令牌"选项'
  },
  {
    title: '创建令牌',
    desc: '点击"生成令牌"按钮'
  },
  {
    title: '设置信息',
    desc: '填写令牌名称，选择有效期'
  },
  {
    title: '保存令牌',
    desc: '生成后立即保存令牌（仅显示一次）'
  }
]

// 注意事项
const oauthNotices = [
  '应用需要通过平台审核',
  '请妥善保管 Client Secret',
  '回调地址需要备案域名',
  '审核通过后即可正常使用'
]

const tokenNotices = [
  '令牌有效期最长 30 天',
  '令牌仅显示一次，请及时保存',
  '请勿泄露访问令牌信息',
  '可随时在平台吊销令牌'
]

const steps = ref([])
const notices = ref([])

// 获取页面参数
onMounted(() => {
  const pages = getCurrentPages()
  const currentPage = pages[pages.length - 1]
  const eventChannel = currentPage.getOpenerEventChannel()
  
  // 获取传递的类型参数
  type.value = currentPage.$page.options.type || 'oauth'
  
  // 根据类型设置对应的步骤和提示
  steps.value = type.value === 'oauth' ? oauthSteps : tokenSteps
  notices.value = type.value === 'oauth' ? oauthNotices : tokenNotices
})

// 页面标题计算属性
const pageTitle = computed(() => {
  return type.value === 'oauth' ? '应用授权指南' : '访问令牌指南'
})

// 底部按钮文本计算属性
const actionButtonText = computed(() => {
  return type.value === 'oauth' ? '前往应用管理' : '生成访问令牌'
})

const handleBack = () => {
  uni.navigateBack()
}

const handleAction = () => {
  // 处理操作按钮点击
  uni.showToast({
    title: '功能开发中...',
    icon: 'none'
  })
}
</script>

<style scoped>
.guide-page {
  min-height: 100vh;
  background: #f8f9fa;
  padding-bottom: 120rpx;
}

.guide-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  height: 88rpx;
  display: flex;
  align-items: center;
  padding: 0 30rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

.back-btn {
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon {
  font-size: 40rpx;
  color: #2c3e50;
}

.header-title {
  flex: 1;
  text-align: center;
  font-size: 32rpx;
  font-weight: 600;
  color: #2c3e50;
  margin-right: 60rpx;
}

.guide-content {
  padding: 30rpx;
}

.steps-container {
  background: #fff;
  border-radius: 24rpx;
  padding: 24rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
}

.step-item {
  display: flex;
  padding: 24rpx 0;
  border-bottom: 2rpx solid #f1f3f5;
}

.step-item:last-child {
  border-bottom: none;
}

.step-number {
  width: 48rpx;
  height: 48rpx;
  background: linear-gradient(135deg, #00C853, #00B248);
  border-radius: 24rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 28rpx;
  font-weight: 600;
  margin-right: 20rpx;
  flex-shrink: 0;
}

.step-content {
  flex: 1;
}

.step-title {
  font-size: 30rpx;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 8rpx;
  display: block;
}

.step-desc {
  font-size: 26rpx;
  color: #606f7b;
  line-height: 1.6;
}

.notice-section {
  background: #fff;
  border-radius: 24rpx;
  padding: 24rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
}

.notice-title {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
  font-size: 30rpx;
  font-weight: 600;
  color: #2c3e50;
}

.notice-icon {
  margin-right: 12rpx;
}

.notice-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 16rpx;
}

.dot {
  margin-right: 12rpx;
  color: #00C853;
  font-weight: bold;
}

.notice-text {
  flex: 1;
  font-size: 26rpx;
  color: #606f7b;
  line-height: 1.6;
}

.guide-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24rpx 40rpx;
  background: #fff;
  box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
}

.action-btn {
  height: 88rpx;
  background: linear-gradient(135deg, #00C853, #00B248);
  border-radius: 44rpx;
  color: #fff;
  font-size: 32rpx;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4rpx 16rpx rgba(0, 200, 83, 0.3);
  border: none;
}

.action-btn:active {
  transform: translateY(2rpx);
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.2);
}
</style>